/**
 * Copyright (C) 2010 David Simonek <dafesimonek@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MaterialsActionsPanel.java
 *
 * Created on Jul 30, 2010, 2:44:57 PM
 */

package org.dafe.partyband.gui.songs;

import java.util.List;
import javax.swing.Action;
import org.dafe.partyband.db.api.ISongResource;
import org.dafe.partyband.gui.exports.ExportWizardAction;
import org.dafe.partyband.gui.songs.MaterialsTable.MaterialsModel;
import org.dafe.partyband.importer.api.IImporterServices;
import org.dafe.partyband.importer.api.IMimeTypeDetector;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;

/**
 *
 * @author dafe
 */
public class MaterialsActionsPanel extends javax.swing.JPanel {

    private static final IMimeTypeDetector mimeDetector = Lookup.getDefault().lookup(IImporterServices.class).getMimeDetector();

    private final Action addAction;
    private final Action deleteAction;
    private final ExportWizardAction exportAction;
    private final Action playMp3Action;
    private final Action openAction;
    private final Action printAction;
    private final Action findResourcesAction;

    /** Creates new form MaterialsActionsPanel */
    public MaterialsActionsPanel(Lookup materialsLkp, Lookup curSongLkp, MaterialsModel materialsModel) {
        initComponents();

        playMp3Action = ActionsFactory.createPlayMp3MaterialAction(materialsLkp, curSongLkp);
        materialPane.add(playMp3Action);
        openAction = ActionsFactory.createOpenMaterialsAction(materialsLkp);
        materialPane.add(openAction);
        exportAction = new ExportWizardAction(NbBundle.getMessage(SongsTable.class, "ACT_ExportSongs"), materialsLkp);
        materialPane.add(exportAction);
        printAction = ActionsFactory.createPrintMaterialsAction(materialsLkp,
                NbBundle.getMessage(MaterialsActionsPanel.class, "ACT_PrintMaterials"),
                NbBundle.getMessage(ActionsFactory.class, "HINT_PrintMaterials"));
        materialPane.add(printAction);
        deleteAction = ActionsFactory.createDeleteMaterialsAction(materialsLkp, materialsModel, this);
        materialPane.add(deleteAction);
        findResourcesAction = ActionsFactory.createFindMaterialsAction(curSongLkp, materialsModel, this);
        newContentPane.add(findResourcesAction);
        addAction = ActionsFactory.createAddMaterialsAction(materialsModel, this);
        newContentPane.add(addAction);

        scrollPane.setViewportBorder(null);
    }

    public Action getAddAction() {
        return addAction;
    }

    public Action getDeleteAction() {
        return deleteAction;
    }

    public ExportWizardAction getExportAction() {
        return exportAction;
    }

    public Action getOpenAction() {
        return openAction;
    }

    public Action getPrintAction() {
        return printAction;
    }

    public Action getFindResourcesAction() {
        return findResourcesAction;
    }

    public void setCurMaterials (List<ISongResource> songRes) {
        int count = songRes.size();
        if (count == 0) {
            materialPane.setTitle(NbBundle.getMessage(MaterialsActionsPanel.class,
                    "MaterialsActionsPanel.materialPane.title"));
        } else if (count == 1) {
            ISongResource res = songRes.get(0);
            materialPane.setTitle(mimeDetector.getMimeDisplayName(res.getMimeType()));
        } else {
            materialPane.setTitle(NbBundle.getMessage(MaterialsActionsPanel.class,
                    "MaterialsActionsPanel.materialPane.multiple"));
        }
    }

    public Action getPlayMp3Action () {
        return playMp3Action;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        scrollPane = new javax.swing.JScrollPane();
        taskContainer = new org.jdesktop.swingx.JXTaskPaneContainer();
        materialPane = new org.jdesktop.swingx.JXTaskPane();
        newContentPane = new org.jdesktop.swingx.JXTaskPane();

        setMinimumSize(new java.awt.Dimension(0, 0));

        materialPane.setToolTipText(org.openide.util.NbBundle.getMessage(MaterialsActionsPanel.class, "MaterialsActionsPanel.materialPane.toolTipText", new Object[] {})); // NOI18N
        materialPane.setTitle(org.openide.util.NbBundle.getMessage(MaterialsActionsPanel.class, "MaterialsActionsPanel.materialPane.title", new Object[] {})); // NOI18N
        taskContainer.add(materialPane);

        newContentPane.setToolTipText(org.openide.util.NbBundle.getMessage(MaterialsActionsPanel.class, "MaterialsActionsPanel.newContentPane.toolTipText", new Object[] {})); // NOI18N
        newContentPane.setTitle(org.openide.util.NbBundle.getMessage(MaterialsActionsPanel.class, "MaterialsActionsPanel.newContentPane.title", new Object[] {})); // NOI18N
        taskContainer.add(newContentPane);

        scrollPane.setViewportView(taskContainer);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(scrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(scrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.jdesktop.swingx.JXTaskPane materialPane;
    private org.jdesktop.swingx.JXTaskPane newContentPane;
    private javax.swing.JScrollPane scrollPane;
    private org.jdesktop.swingx.JXTaskPaneContainer taskContainer;
    // End of variables declaration//GEN-END:variables

}
